// pages/homeFM/homeFM.js

import {
  reqHomeHeartKnowledge
} from '../../api/homeHeartKnowledge'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    // 是否正在加载
    loading: 0,
    // 是否加载结束
    isEnd: false,
    cur: 1,
    pageSize: 12,
    arr: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  async getData() {
    // let {channelId,pageNo,pageSize} = this.data;
    let res = await reqHomeHeartKnowledge({
      _page: this.data.cur,
      _limit: this.data.pageSize
    });
    if (res.length == 0) {
      this.setData({
        loading: 2
      });
    } else {
      this.setData({
        loading: 0
      });
    }
    this.setData({
      arr: [...this.data.arr, ...res]
    })
  },
  goBack(){
    wx.navigateBack();
  },
  onReachBottom() {
    let page = this.data.cur + 1;
    if (this.data.loading == 2) {
      return;
    }
    this.setData({
      cur: page,
      loading: 1
    })
    this.getData();
  },
})